package com.redstar.HappyRefresh.service.impl;

import com.redstar.HappyRefresh.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService { // 邮箱服务

    @Autowired
    private SimpleMailMessage simpleMailMessage; // 邮箱信息工具类
    @Autowired
    private JavaMailSender javaMailSender; // 发送邮箱工具类
    @Value("${spring.mail.username}")
    private String from;

    @Override
    @Async
    public void send(String email, String context) {
        try {
            simpleMailMessage.setSubject("乐刷视频");
            simpleMailMessage.setFrom(from);
            simpleMailMessage.setTo(email);
            simpleMailMessage.setText(context);
            javaMailSender.send(simpleMailMessage);
        } catch (Exception e) {
            throw new RuntimeException("send方法出错：" + e.getMessage());
        }
    }
}
